import request from '@/utils/request'

export function changeStatus(params) {
  return request({
    url: '/v1/todo/' + params.id,
    method: 'put',
  })
}

export function getData() {
  return request({
    url: '/v1/todo',
    method: 'get'
  })
}

export function removeData(params) {
  return request({
    url: '/v1/todo/' + params.id,
    method: 'delete',
  })
}

export function addData(data) {
  return request({
    url: '/v1/todo',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        ret = ret.substring(0, ret.lastIndexOf('&'))
        return ret
      }
    ],
    async: false,
    data
  })

}
